<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud
      :options="options"
      :columns="columns"
      ref="crudRef"
      @select="selectids"
    >
    </ma-crud>
    <a-drawer
      :width="1200"
      :visible="visible"
      @ok="handleOk"
      @cancel="handleCancel"
      unmountOnClose
    >
      <template #title>节点信息</template>
      <inspectionrouteInfo :route_ids="route_ids" v-if="visible">
      </inspectionrouteInfo>
    </a-drawer>
  </div>
</template>
<script setup>
import { ref, reactive, defineEmits } from "vue";
import secureInspectionrouteManage from "@/api/secure/secureInspectionrouteManage";
import inspectionrouteInfo from "@/views/secure/inspectionrouteInfo/index.vue";
import { Message } from "@arco-design/web-vue";
import tool from "@/utils/tool";
import * as common from "@/utils/common";

const crudRef = ref();
const route_ids = ref();
const visible = ref(false);
const emits = defineEmits(["therr"]);

const numberOperation = (newValue, id, numberName) => {
  secureInspectionrouteManage
    .numberOperation({ id, numberName, numberValue: newValue })
    .then((res) => {
      res.success && Message.success(res.message);
    })
    .catch((e) => {
      console.log(e);
    });
};

const handleOk = () => {
  visible.value = false;
};
const handleCancel = () => {
  visible.value = false;
};
const selectids = (row) => {
  emits('therr',row)
  console.log(row);
};

const switchStatus = (statusValue, id, statusName) => {
  secureInspectionrouteManage
    .changeStatus({ id, statusName, statusValue })
    .then((res) => {
      res.success && Message.success(res.message);
    })
    .catch((e) => {
      console.log(e);
    });
};

const options = reactive({
  id: "flyos_secure_inspectionroute_manage",
  rowSelection: {
    showCheckedAll: true,
  },
  pk: "id",
  operationColumn: false,
  operationWidth: 160,
  formOption: {
    viewType: "modal",
    width: 600,
  },
  api: secureInspectionrouteManage.getList,
  recycleApi: secureInspectionrouteManage.getRecycleList,
  // add: {
  //   show: true,
  //   api: secureInspectionrouteManage.save,
  //   auth: ["secure:inspectionrouteManage:save"],
  // },
  // edit: {
  //   show: true,
  //   api: secureInspectionrouteManage.update,
  //   auth: ["secure:inspectionrouteManage:update"],
  // },
  // delete: {
  //   show: true,
  //   api: secureInspectionrouteManage.deletes,
  //   auth: ["secure:inspectionrouteManage:delete"],
  //   realApi: secureInspectionrouteManage.realDeletes,
  //   realAuth: ["secure:inspectionrouteManage:realDeletes"],
  // },
  recovery: {
    show: true,
    api: secureInspectionrouteManage.recoverys,
    auth: ["secure:inspectionrouteManage:recovery"],
  },
  // import: {
  //   show: true,
  //   url: "secure/inspectionrouteManage/import",
  //   templateUrl: "secure/inspectionrouteManage/downloadTemplate",
  //   auth: ["secure:inspectionrouteManage:import"],
  // },
  // export: {
  //   show: true,
  //   url: "secure/inspectionrouteManage/export",
  //   auth: ["secure:inspectionrouteManage:export"],
  // },
});

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入ID",
    },
  },
  {
    title: "路线名称",
    dataIndex: "route_name",
    formType: "input",
    search: false,
    commonRules: {
      required: true,
      message: "请输入路线名称",
    },
  },
  {
    title: "时间段",
    dataIndex: "route_time",
    formType: "time",
    search: false,
    commonRules: {
      required: true,
      message: "请输入时间段",
    },
    range: true,
  },
  {
    title: "节点信息",
    dataIndex: "not_node_info",
    addDisplay: false,
    editDisplay: false,
  },
  {
    title: "重复类型",
    dataIndex: "not_status_type",
    addDisplay: false,
    editDisplay: false,
  },
  {
    title: "是否重复设置",
    dataIndex: "not_status",
    formType: "radio",
    hide: true,
    control: (val) => {
      if (val == 1) {
        return {
          days: { display: false },
          weekly: { display: false },
        };
      }
      if (val == 2) {
        return {
          days: { display: true },
          weekly: { display: true },
        };
      }
    },
    search: false,
    commonRules: {
      required: true,
      message: "请输入是否重复设置",
    },
    dict: {
      name: "xjlxtf",
      props: {
        label: "title",
        value: "key",
      },
      translation: true,
    },
  },
  {
    title: "每天次数",
    dataIndex: "days",
    formType: "input",
    hide: true,
  },
  {
    title: "每周次数",
    dataIndex: "weekly",
    formType: "input",
    hide: true,
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "textarea",
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true,
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true,
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true,
  },
]);
</script>
<script>
export default { name: "secure:inspectionrouteManage" };
</script>
